let vm = new Vue({
    el: "#app",
    data: {
        count: 0, // 购物车数量
        search: "", // 搜索框输入的内容
        isLogin: false, // 当前是否有用户登录
        user: {}, // // 当前登录的用户信息
        banners: [], // 轮播图
        categories: [] // 全部商品分类
    },
    created: function () {
        // 获取登录的用户信息
        axios.get("/user/getlogin").then(function (response) {
            vm.user = response.data;
            vm.isLogin = response.data != "";
        });

        // 全部商品分类
        axios.get("/category/selectAll").then(function (response) {
            vm.categories = response.data;
        });

        // 购物车里的商品数量
        axios.get("/shop_cart/selectCount").then(function (response) {
            vm.count = response.data;
        });

        // 全部商品分类
        axios.get("/banner/selectAll").then(function (response) {
            vm.banners = response.data;
        });
    },
    methods: {
        select() {
            location.href = "/list.html?name=" + vm.search;
        },
        logout() {
            axios.get("/user/logout").then(function (response) {
                if (response.data.code === 200) {
                    location.href = "/login.html";
                } else {
                    alert(response.data.msg);
                }
            });
        }
    }
});